﻿using System;
using System.Collections.Specialized;
using System.Configuration;
using Yunzuan.Foundation.Common;
using Yunzuan.Foundation.DataAccess;

namespace Yunzuan.Foundation.Web
{
    public static class GlobalConfig
    { 
        #region 公用配置
        /// <summary>
        /// 查宝网地址
        /// </summary>
        public static string BaseCheckgemsUrl = ConfigurationManager.AppSettings["BaseCheckgemsUrl"]; //查宝网地址
        /// <summary>
        /// 查宝网API
        /// </summary>
        public static string CheckgemsBaseAPI = ConfigurationManager.AppSettings["CheckgemsBaseAPI"]; //上传裸钻图片密钥
        /// <summary>
        /// 获取裸钻图片
        /// </summary>
        public static string GetImageInfoAPIURL = CheckgemsBaseAPI+ConfigurationManager.AppSettings["CheckgemsAPIURL"]; //上传裸钻图片密钥
      
        /// <summary>
        /// 上传裸钻图片密钥
        /// </summary>
        public static string DiamonImgAccessSecret = ConfigurationManager.AppSettings["DiamonImgAccessSecret"]; //上传裸钻图片密钥
        /// <summary>
        /// 上传裸钻图片密钥
        /// </summary>
        public static string DiamonImgAccessKey = ConfigurationManager.AppSettings["DiamonImgAccessKey"]; //上传裸钻图片密钥
        /// <summary>
        /// 上传裸钻图片地址
        /// </summary>
        public static string TransDiamondImgUrl = ConfigurationManager.AppSettings["TransDiamondImgUrl"]; //上传裸钻图片地址

        /// <summary>
        /// 小模块功能相关baseUrl，调用建国的测试ip
        /// </summary>
        public static string PlugInBaseUrl = ConfigurationManager.AppSettings["PlugInBaseUrl"]; //小模块功能相关，调用建国的测试ip
         //<!--销售报告访问-->
        public static string SalesReportVisitUrl = PlugInBaseUrl + ConfigurationManager.AppSettings["SalesReportVisitUrl"];
        //<!--销售报告订单-->
        public static string SalesReportOrderUrl = PlugInBaseUrl + ConfigurationManager.AppSettings["SalesReportOrderUrl"];
        //--销售报告利润-->
        public static string SalesReportProfitUrl = PlugInBaseUrl + ConfigurationManager.AppSettings["SalesReportProfitUrl"];
        //<!--销售报告延期-->
        public static string SalesReportDelayUrl = PlugInBaseUrl + ConfigurationManager.AppSettings["SalesReportDelayUrl"];
        //<!--销售报告资产-->
        public static string SalesReportAssetsUrl = PlugInBaseUrl + ConfigurationManager.AppSettings["SalesReportAssetsUrl"];
 

        public static string BaseURL = ConfigurationManager.AppSettings["TransmissionBaseURL"]; //数据仓库库存传输使用URL

        /// <summary>
        /// 供应商URL
        /// </summary>
        public static string SuppliersUrl = BaseURL + ConfigurationManager.AppSettings["DataCenter.SuppliersUrl"];


        public static string ParcelsUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionParcelsURL"];//统包货的搜索 11-7

        public static string TransmissionUpStockURL = BaseURL + ConfigurationManager.AppSettings["TransmissionUpStockURL"]; // 编辑 ,(删除 ,上传，新增,也用这个)现货库存URL

        /// <summary>
        /// 数据仓库批量修改退点使用URL
        /// </summary>
        public static string TransmissionUpBatchUrl = TransmissionUpStockURL + ConfigurationManager.AppSettings["TransmissionUpBatchUrl"];  //stocks/prices/

        public static string TransmissionBatchUpStockURL = BaseURL + ConfigurationManager.AppSettings["TransmissionBatchUpStockURL"];//批量调整裸钻 PUT




        public static int ExpirationTimeOut = int.Parse(ConfigurationManager.AppSettings["ExpirationTimeOut"]);//过期时间       

        /// 数据仓库库存传输使用URL
        /// </summary>
        public static string IUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionInventoryURL"];

        /// <summary>
        /// 数据仓库订单传输使用URL
        /// </summary>
        public static string OUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionOrderURL"];

        /// <summary>
        /// 图片上传
        /// </summary>
        public static string TransmissionImageUploadUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionImageUploadUrl"];

        /// <summary>
        /// 视频上传
        /// </summary>
        public static string TransmissionVideoUploadUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionVideoUploadUrl"];
        /// <summary>
        /// 上下架地址
        /// </summary>
        public static string OnShelvesOrOffShelvesUrl = BaseURL + ConfigurationManager.AppSettings["OnShelvesOrOffShelvesUrl"];

        /// <summary>
        /// 供应商供应商列表(全称，简称)查看
        /// </summary>
        public static string TransmissionSuppliersUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionSuppliersUrl"];

        public static string TransmissionSuppliersBlackListUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionSuppliersBlackListUrl"];

        /// <summary>
        /// 供应商供应商列表设置多个供应商
        /// </summary>
        public static string TransmissionSuppliersSetUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionSuppliersSetUrl"];

        /// <summary>
        /// 供应商供应商列表设置（{0},替换为空即可）单个供应商
        /// </summary>
        public static string TransmissionSupplierSetUrl = TransmissionSuppliersSetUrl + ConfigurationManager.AppSettings["TransmissionSupplierSetUrl"];  //单个url为:baseUrl+多个URL+自己url

        public static string TransmissionSupplierWhiteSetUrl = TransmissionSuppliersSetUrl + ConfigurationManager.AppSettings["TransmissionSupplierWhiteSetUrl"];  //单个url为:baseUrl+多个URL+自己url

        ///<summary>
        ///成品列表搜索
        ///</summary>
        public static string TransmissionInlaysSearchUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionInlaysSearchUrl"];


        /// <summary>
        ///裸钻 POST/PUT/GET/DELETE 跟其它产品如TransmissionInlaysOprateUrl等统一，就不在web.config里面加 stock/{0} 
        /// </summary>
        public static string TransmissionStockOprateUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionUpStockURL"] +"{0}";

        /// <summary>
        ///成品 POST/PUT/GET/DELETE
        /// </summary>
        public static string TransmissionInlaysOprateUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionInlaysOprateUrl"];

        //成品导入
        public static string TransmissionInlaysImportUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionInlaysImportUrl"];
        ///<summary>
        ///空托列表搜索
        ///</summary>
        public static string TransmissionInlaySettingsSearchUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionInlaySettingsSearchUrl"]; 
        /// <summary>
        ///空托 POST/PUT/GET/DELETE
        /// </summary>
        public static string TransmissionInlaySettingsOprateUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionInlaySettingsOprateUrl"];

        //空托导入
        public static string TransmissionInlaySettingsImportUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionInlaySettingsImportUrl"];

        /// <summary>
        /// 彩宝操作POST/PUT/GET/DELETE
        /// </summary>
        public static string TransmissionGemOprateUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionGemOprateUrl"];
        /// <summary>
        /// 彩宝filter
        /// </summary>
        public static string TransmissionGemSearchUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionGemSearchUrl"];
        /// <summary>
        /// 彩宝上传
        /// </summary>
        public static string TransmissionGemsImportUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionGemsImportUrl"];

        /// <summary>
        /// 翡翠操作POST/PUT/GET/DELETE
        /// </summary>
        public static string TransmissionEmeraldOprateUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionEmeraldOprateUrl"];
        /// <summary>
        /// 翡翠filter
        /// </summary>
        public static string TransmissionEmeraldSearchUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionEmeraldSearchUrl"];
        /// <summary>
        /// 翡翠上传
        /// </summary>
        public static string TransmissionEmeraldsImportUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionEmeraldsImportUrl"];

        /// <summary>
        /// 素金操作POST/PUT/GET/DELETE
        /// </summary>
        public static string TransmissionPrimeGoldsOprateUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionPrimeGoldsOprateUrl"];
        /// <summary>
        /// 素金filter
        /// </summary>
        public static string TransmissionPrimeGoldsSearchUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionPrimeGoldsSearchUrl"];
        /// <summary>
        /// 素金上传
        /// </summary>
        public static string TransmissionPrimeGoldsImportUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionPrimeGoldsImportUrl"]; 
        /// <summary>
        /// 素金改价
        /// </summary>
        public static string TransmissionPrimeGoldsPrice = BaseURL + ConfigurationManager.AppSettings["TransmissionPrimeGoldsPrice"];
        ///<summary>
        ///统包货列表搜索
        ///</summary>
        public static string TransmissionParcelsSearchUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionParcelsSearchUrl"];//仓库签名用的Secret

        /// <summary>
        //////统包货 POST/PUT/GET/DELETE
        /// </summary>
        public static string TransmissionParcelOprateUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionParcelOprateUrl"];//仓库签名用的Secret
        /// <summary>
        /// 统包上传
        /// </summary>
        public static string TransmissionParcelsImportUrl = BaseURL + ConfigurationManager.AppSettings["TransmissionParcelsImportUrl"];//仓库签名用的Secret
         

        //得到数据中心导出的地址
        public static string GetExportUrl = BaseURL + ConfigurationManager.AppSettings["GetExportUrl"];//导出stocks/archives/  
        //导出
        public static string ExportPort = ConfigurationManager.AppSettings["ExportPort"];//导出archives/  

        public static string filters = ConfigurationManager.AppSettings["partUrl"];
        //短信相关
        /// <summary>
        /// api url
        /// </summary>
        public static string SMSurl = ConfigurationManager.AppSettings["SMSurl"];
        /// <summary>
        /// appkey
        /// </summary>
        public static string SMSappkey = ConfigurationManager.AppSettings["SMSappkey"];
        /// <summary>
        /// secret
        /// </summary>
        public static string SMSsecret = ConfigurationManager.AppSettings["SMSsecret"];




        /// </summary>
        public static string SMSTemplateByOrders = ConfigurationManager.AppSettings["SMSTemplateByOrders"];
        /// <summary>
        /// 下单提醒模板内容${salesname}您好，${customer}于${time}下单成功：货号为${sn}
        /// </summary>
        public static string SMSTemplateByOrdersContent = ConfigurationManager.AppSettings["SMSTemplateByOrdersContent"];

        /// <summary>
        /// 已注册提醒模板
        /// </summary>
        public static string SMSTemplateByHasReg = ConfigurationManager.AppSettings["SMSTemplateByHasReg"];
        /// <summary>
        /// 已注册提醒模板内容${adminname}${name}            //${adminname}您好，${name}已申请注册成功，请尽快审核
        /// </summary>
        public static string SMSTemplateByHasRegContent = ConfigurationManager.AppSettings["SMSTemplateByHasRegContent"];


        /// <summary>
        /// 到货提醒模
        /// </summary>
        public static string SMSTemplateByOrderArrival = ConfigurationManager.AppSettings["SMSTemplateByOrderArrival"];
        /// <summary>
        /// 到货提醒模内容${salesname}            //  <!-- 到货提醒模板您好:您好,您预定的货号为${sn}现已到货-->
        /// </summary>
        public static string SMSTemplateByOrderArrivalContent = ConfigurationManager.AppSettings["SMSTemplateByOrderArrivalContent"];

        /// <summary>
        /// 到货提醒模
        /// </summary>
        public static string SMSTemplateByLendOrder = ConfigurationManager.AppSettings["SMSLendOrders"];
        /// <summary>
        /// 到货提醒模内容${salesname}            //  <!-- 到货提醒模板您好:您好,您预定的货号为${sn}现已到货-->
        /// </summary>
        public static string SMSTemplateByLendOrderContent = ConfigurationManager.AppSettings["SMSLendOrdersContent"];

        /// <summary>
        /// 注册后审核成功提醒模版
        /// </summary>
        public static string SMSTemplateByReview = ConfigurationManager.AppSettings["SMSTemplateByReview"];//客户主动注册后提醒到管理员 8-30


        /// <summary>
        /// 注册后审核成功提醒模版${customername}            //${customername}您好，，您的注册申请已审核通过，感谢您注册
        /// </summary>
        public static string SMSTemplateByReviewContent = ConfigurationManager.AppSettings["SMSTemplateByReviewContent"];//客户主动注册后提醒到管理员 8-30



        /// <summary>
        /// 客户系统开通开放平台接口的短信 
        /// </summary>
        public static string SMSCustomerOpenAPI = ConfigurationManager.AppSettings["SMSCustomerOpenAPI"];//


        /// <summary>
        /// 客户系统开通开放平台接口的短信模版         //超级管理员，供应商${name}已开通${customer}的api接口服务
        /// </summary>
        public static string SMSCustomerOpenAPIContent = ConfigurationManager.AppSettings["SMSCustomerOpenAPIContent"];//


        /// <summary>
        /// 到货提醒模板-新
        /// </summary>
        public static string SMSArrivalOrders = ConfigurationManager.AppSettings["SMSArrivalOrders"];//
        /// <summary>
        /// 到货提醒模板-新  内容${salesname}您好，您有(${supplier})的订单到货，请及时到系统查看并安排出货事宜
        /// </summary>
        public static string SMSArrivalOrdersContent = ConfigurationManager.AppSettings["SMSArrivalOrdersContent"];//


        /// <summary>
        /// 多级下单失败提醒
        /// </summary>
        public static string SMSSubmitOrderError = ConfigurationManager.AppSettings["SMSSubmitOrderError"];//
        /// <summary>
        /// 多级下单失败提醒  客户${name}下供应商${supplier}的货：${SN} 失败，请与供应商确认
        /// </summary>
        public static string SMSSubmitOrderErrorContent = ConfigurationManager.AppSettings["SMSSubmitOrderErrorContent"];//

        public static int BanSearchMinutes = ConfigurationManager.AppSettings["BanSearchMinutes"]!=null? int.Parse(ConfigurationManager.AppSettings["BanSearchMinutes"].ToString()):2 ;//
        public static int BanSearchCount = ConfigurationManager.AppSettings["BanSearchCount"] != null ? int.Parse(ConfigurationManager.AppSettings["BanSearchCount"].ToString()) : 5;//
        /// <summary>
        ///库存报告
        /// </summary>
        public static string StockBaseUrl = ConfigurationManager.AppSettings["AssessmentsBaseUrl"];//库存报告
        public static string StocksReportsUrl = StockBaseUrl + ConfigurationManager.AppSettings["StocksReportsUrl"];//库存报告
        public static string AssessmentsUrl = StockBaseUrl+ ConfigurationManager.AppSettings["AssessmentsUrl"];//库存报告
        public static string DownloadReportUrl = StockBaseUrl + ConfigurationManager.AppSettings["DownloadReportUrl"];//库存报告
        public static string StockPricesAdjusterUrl = StockBaseUrl + ConfigurationManager.AppSettings["StockPricesAdjusterUrl"];//库存报告
        public static string StockRequirementUrl = StockBaseUrl + ConfigurationManager.AppSettings["StockRequirementUrl"];//库存必备
        //<!--DpiPointer-->
        public static string SalesDpiPointerUrl = StockBaseUrl + ConfigurationManager.AppSettings["SalesDpiPointerUrl"];

        public static string ContactsAvailableUrl = StockBaseUrl + ConfigurationManager.AppSettings["ContactsAvailableUrl"];
        public static string ValuationErpUrl = StockBaseUrl + ConfigurationManager.AppSettings["ValuationErpUrl"];
        public static string ValuationGoldUrl = StockBaseUrl + ConfigurationManager.AppSettings["ValuationGoldUrl"];
        public static string ValuationSecondaryUrl = StockBaseUrl + ConfigurationManager.AppSettings["ValuationSecondaryUrl"];

        public static string BanningStatus = ConfigurationManager.AppSettings["BanningStatus"];//禁止下单状态

        public static string TransmissionBatch = ConfigurationManager.AppSettings["TransmissionBatch"];//批量修改
        public static string TransmissionBatchDelete = ConfigurationManager.AppSettings["TransmissionBatchDelete"];//批量删除
        public static string TransmissionPrices = ConfigurationManager.AppSettings["TransmissionUpBatchUrl"];  //stocks/prices/

        public static string WhiteSupplierUrl = ConfigurationManager.AppSettings["WhiteSupplierUrl"];


        /// <summary>
        ///注册验证码模板  
        /// </summary>
        public static string SMSTemplateByReg = ConfigurationManager.AppSettings["SMSTemplateByReg"];
        /// <summary>
        /// 注册验证码模板您的验证码：${code}，${min}分钟内输入有效，感谢您申请注册
        /// </summary>
        public static string SMSTemplateByRegContent = ConfigurationManager.AppSettings["SMSTemplateByRegContent"];

        /// <summary>
        ///登陆验证码模板  
        /// </summary>
        public static string SMSLogin = ConfigurationManager.AppSettings["SMSLogin"];
        /// <summary>
        /// 注册验证码模板您的验证码：${code}，${min}分钟内输入有效，感谢您申请注册
        /// </summary>
        public static string SMSLoginContent = ConfigurationManager.AppSettings["SMSLoginContent"];



        public static string IsValidPwd = ConfigurationManager.AppSettings["IsValidPwd"];


        public static int SearchCount = ConfigurationManager.AppSettings["SearchCount"] == null ? 100 : int.Parse(ConfigurationManager.AppSettings["SearchCount"]);



        public static string BlackaListURL = ConfigurationManager.AppSettings["BlackListUrl"] == null ? "~/App_Data/BlackList.xml" : ConfigurationManager.AppSettings["BlackListUrl"];

        //查询所有商品库存
        public static string GetAllProductsURL = BaseURL + ConfigurationManager.AppSettings["GetAllProductsURL"];

        #endregion
        public static string SupplierDB = ConfigurationManager.AppSettings["SupplierDB"];

        public static void reLoadKey(string key)
        {
            try
            {
                if (System.Web.HttpContext.Current.Cache.Get("Cache:key" + key) == null || System.Web.HttpContext.Current.Cache.Get("Cache:AccessKey" + key) == null || System.Web.HttpContext.Current.Cache.Get("Cache:AccessSecret" + key) == null)
                {
                    ConfigSettings config = (ConfigurationManager.GetSection(key) as ConfigSettings);
                    if (config == null) return;
                    config = (ConfigurationManager.GetSection(key) as ConfigSettings);
                    System.Web.HttpContext.Current.Cache.Insert("Cache:key" + key, key, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromDays(1));
                    System.Web.HttpContext.Current.Cache.Insert("Cache:AccessKey" + key, config.TransmissionAccessKey, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromDays(1)); //仓库签名用的key
                    System.Web.HttpContext.Current.Cache.Insert("Cache:AccessSecret" + key, config.TransmissionAccessSecret, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromDays(1));//仓库签名用的Secret
                }
            }
            catch (Exception ex)
            {
                throw;
            }
           
        }
        ///// <summary>
        ///// 通过临时key得到父类key（基类），系统类型（上级是批发还是零售），及自己真实的供应商key
        ///// </summary>
        ///// <param name="key"></param>
        ///// <param name="supplierKey"></param>
        ///// <param name="sysType"></param>
        ///// <param name="secondSn"></param>
        //private static void GetAllKeysByPreKey(string key, out string supplierKey, out string sysType, out string secondSn)
        //{
        //    if (key.Contains("__"))
        //    {
        //        var allKey = key.Split(new string[] { "__" }, StringSplitOptions.None); //按类型与key分割
        //        var newKey = allKey[0].Split('_'); //key
        //                                           //父类key
        //        supplierKey = newKey[0];
        //        //系统类型
        //        sysType = allKey[1];
        //        //真实的供应商key
        //        secondSn = newKey[1];
        //    }
        //    else
        //    {
        //        supplierKey = key;
        //        //系统类型
        //        sysType = "";
        //        //真实的供应商key
        //        secondSn = "";
        //    }
        //}
        /// <summary>
        /// 缓存数据中心对应的AK
        /// </summary>
        /// <param name="key"></param>
        private static void CacheAK(string key, ConfigSettings config)
        {
            if (System.Web.HttpContext.Current.Cache.Get("Cache:key" + key) == null || System.Web.HttpContext.Current.Cache.Get("Cache:AccessKey" + key) == null || System.Web.HttpContext.Current.Cache.Get("Cache:AccessSecret" + key) == null)
            {
               
                System.Web.HttpContext.Current.Cache.Insert("Cache:key" + key, key, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromDays(1));
                System.Web.HttpContext.Current.Cache.Insert("Cache:AccessKey" + key, config.TransmissionAccessKey, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromDays(1)); //仓库签名用的key
                System.Web.HttpContext.Current.Cache.Insert("Cache:AccessSecret" + key, config.TransmissionAccessSecret, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromDays(1));//仓库签名用的Secret
            }
        }

    }
}
